<template>
  <div class="app-container">


    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane v-for="type in feeTypeOptions"
                   :label="type.dictLabel"
                   :name="type.dictValue + ''" >
      </el-tab-pane>
    </el-tabs>


    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="关键字" prop="realName">
        <el-input v-model="queryParams.realName" placeholder="请输入姓名或者手机号或户号" clearable size="mini" style="width:200px;"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="查询时间"  v-if="this.$route.query.state!=1">
        <el-date-picker v-model="dateRange" size="mini" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link  v-if="queryParams.state=='0'" :to="'/property/estate/rooms?estateId=' + queryParams.estateId+'&qianfei=0'" class="link-type">
          <el-button icon="el-icon-back" size="mini">
            返 回
          </el-button>
        </router-link>
        <router-link  v-if="queryParams.state==undefined" :to="'/property/estate/rooms?estateId=' + queryParams.estateId" class="link-type">
          <el-button icon="el-icon-back" size="mini">
            返 回
          </el-button>
        </router-link>
        <router-link  v-if="queryParams.state=='1'" :to="'/property/estate/rooms?estateId=' + queryParams.estateId+'&qianfei=1'" class="link-type">
          <el-button icon="el-icon-back" size="mini">
            返 回
          </el-button>
        </router-link>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="small" @click="handleAdd"
                   v-hasPermi="['module:feeOrderTemp:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon" type="success" size="small" @click.stop="handleAddTempByYear()">按年生成物业费
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon" type="primary" size="small" @click.stop="daoru1()">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon" type="warning" size="small" @click.stop="daochu1()">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon" type="success" size="small" @click.stop="caozuo1()">操作</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon" type="" size="small" @click.stop="tongji1()">统计</el-button>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'danger'">{{'应收费：' + totalFee[0] }}</el-tag>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'danger'">{{'待收费：' + totalFee[1] }}</el-tag>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'success'">{{'应收物业费：' + totalFee[2] }}</el-tag>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'success'">{{'待收物业费：' + totalFee[3] }}</el-tag>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'primary'">{{'应收水费：' + totalFee[6] }}</el-tag>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'primary'">{{'待收水费：' + totalFee[7] }}</el-tag>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'warning'">{{'应收电费：' + totalFee[4] }}</el-tag>
      </el-col>
      <el-col :span="1.5" v-if="tongji">
        <el-tag style="cursor: pointer" :type="'warning'">{{'待收电费：' + totalFee[5] }}</el-tag>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="templateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="所属小区" align="center" prop="estateName" />
      <el-table-column label="姓名" align="center" prop="realName" />
      <el-table-column label="手机号" align="center" prop="phoneNum" width="110"/>
      <el-table-column label="户号" align="center" prop="roomNo" width="130"/>
      <el-table-column label="线下缴费时间" align="center" prop="payTime" width="250" v-if="this.queryParams.state==2"/>
      <el-table-column label="费用状态" align="center" prop="state" >
        <!--        0 - 未交费  1 - 已交费-->
        <template slot-scope="scope">
          <div>
            <el-tag v-if="scope.row.state === 0" style="cursor: pointer" :type="'warning'">未交费</el-tag>
            <el-tag v-if="scope.row.state === 1" style="cursor: pointer" :type="'success'">已交费</el-tag>
            <el-tag v-if="scope.row.state === 2" style="cursor: pointer" :type="'success'">线下交费</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="是否车库" align="center" prop="state">
        <template slot-scope="scope">
          <div>
            <el-tag v-if="scope.row.isGarage === 0" style="cursor: pointer" :type="''">住宅</el-tag>
            <el-tag v-if="scope.row.isGarage === 1" style="cursor: pointer" :type="'success'">车库</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="房屋类型" align="center" prop="roomType">
        <template slot-scope="scope">
          <div>
            <!--            房屋类型  0 - 高层 1 - 低层 2- 商业 3 - 别墅 4 - 其他-->
            <el-tag v-if="scope.row.roomType === 0" style="cursor: pointer" :type="''">高层</el-tag>
            <el-tag v-if="scope.row.roomType === 1" style="cursor: pointer" :type="''">低层</el-tag>
            <el-tag v-if="scope.row.roomType === 2" style="cursor: pointer" :type="''">商业</el-tag>
            <el-tag v-if="scope.row.roomType === 3" style="cursor: pointer" :type="''">别墅</el-tag>
            <el-tag v-if="scope.row.roomType === 4" style="cursor: pointer" :type="''">其他</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="房屋面积"  v-if="queryParams.feeType === 'wyf'"  align="center" prop="roomArea">
        <template slot-scope="scope">
          <div>{{(scope.row.roomArea!=null ? scope.row.roomArea :'') +'㎡'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="车牌号" v-if="queryParams.feeType === 'car'" align="center" prop="carNum" width="100"/>
      <el-table-column label="费用类型" align="center" prop="feeType" width="100">
        <!--        wyf - 物业费 rubbish - 垃圾处理费 car - 车位费  water - 水费 ，eletrict - 电费 ，jiaya - 加压费-->
        <template slot-scope="scope">
          <div>
            <el-tag v-if="scope.row.feeType === 'wyf'" style="cursor: pointer" :type="''">物业费</el-tag>
            <el-tag v-if="scope.row.feeType === 'rubbish'" style="cursor: pointer" :type="'success'">垃圾处理费</el-tag>
            <el-tag v-if="scope.row.feeType === 'car'" style="cursor: pointer" :type="'warning'">车位服务费</el-tag>
            <el-tag v-if="scope.row.feeType === 'water'" style="cursor: pointer" :type="'success'">代收水费</el-tag>
            <el-tag v-if="scope.row.feeType === 'jiaya'" style="cursor: pointer" :type="''">供水转换费</el-tag>
            <el-tag v-if="scope.row.feeType === 'eletrict'" style="cursor: pointer" :type="'warning'">代收电费</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="费用时间" align="center" prop="yearNum" width="120">
        <template slot-scope="scope">
          {{ scope.row.yearNum +' 年' +  scope.row.monthNum +' 月' }}
        </template>
      </el-table-column>
      <el-table-column label="单价" align="center" prop="singlePrice">
        <template slot-scope="scope">
          <div>{{  (scope.row.singlePrice != null ? scope.row.singlePrice : 0.00) + '元'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="总价" align="center" prop="totalPrice" width="120">
        <template slot-scope="scope">
          <div>{{ (scope.row.totalPrice != null ? scope.row.totalPrice : 0.00) + '元'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="已支付金额" align="center" prop="paidPrice" width="120">
        <template slot-scope="scope">
          <div>{{(scope.row.paidPrice != null ? scope.row.paidPrice : 0.00) + '元'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="优惠金额" align="center" prop="youhuiPrice">
        <template slot-scope="scope">
          <div>{{ (scope.row.youhuiPrice != null ? scope.row.youhuiPrice : 0.00) + '元'}}</div>
        </template>
      </el-table-column>
      <el-table-column label="数量"  align="center" prop="paidCount" width="80">
        <template slot-scope="scope">
          <div v-if="scope.row.feeType === 'car'">{{ scope.row.paidCount + '个' }}</div>
          <div v-else-if="scope.row.feeType === 'water'">
            {{ '起：' + scope.row.beginCount +'，止：' + scope.row.endCount + ',共'+scope.row.paidCount+'³' }}
          </div>
          <div v-else>{{ scope.row.paidCount }}</div>
        </template>
      </el-table-column>
      <el-table-column label="备注信息" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['module:feeOrderTemp:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['module:feeOrderTemp:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList" />

    <!--操作-->
    <el-dialog
      title="提示"
      :visible.sync="caozuo"
      width="30%"
      :before-close="guanbi3">
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['module:feeOrderTemp:add']">新增</el-button>

        <el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                   v-hasPermi="['module:feeOrderTemp:edit']">修改</el-button>

        <el-button type="success" icon="el-icon-edit" size="mini" :disabled="multiple" @click="handleUpdateState"
                   v-hasPermi="['module:feeOrderTemp:edit']">批量修改交费状态</el-button>

        <el-button type="success" icon="el-icon-edit" size="mini" :disabled="multiple" @click="handleUpdateRemark"
                   v-hasPermi="['module:feeOrderTemp:edit']">批量修改备注信息</el-button>
        <br><br>
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                   v-hasPermi="['module:feeOrderTemp:remove']">删除</el-button>

        <el-button size="mini" @click="guanbi3">取 消</el-button>
      </span>
    </el-dialog>

    <!--导入-->
    <el-dialog
      title="提示"
      :visible.sync="daoru"
      width="30%"
      :before-close="guanbi1">
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleImportWyf"
                   v-hasPermi="['module:feeOrderTemp:import']">导入物业费</el-button>

        <el-button type="success" icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleImportWyfYear"
                   v-hasPermi="['module:feeOrderTemp:import']">导入物业费(按年)</el-button>

        <el-button type="primary" icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleImportSdJ"
                   v-hasPermi="['module:feeOrderTemp:import']">导入水电加压</el-button>
        <el-button size="mini" @click="guanbi1">取 消</el-button>
      </span>
    </el-dialog>

    <!--导出-->
    <el-dialog
      title="提示"
      :visible.sync="daochu"
      width="30%"
      :before-close="guanbi2">
      <span slot="footer" class="dialog-footer">
        <el-button type="warning" icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport"
                   v-hasPermi="['module:feeOrderTemp:export']">导出全部</el-button>

        <el-button type="warning" icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExportAll"
                   v-hasPermi="['module:feeOrderTemp:export']">导出当前</el-button>

        <el-button size="mini" @click="guanbi2">取 消</el-button>
      </span>
    </el-dialog>

    <!-- 添加或修改物业费相关费用的模板对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="24" v-if="tianjia!=true">
            <el-form-item label="费用状态" prop="state">
              <div>
                <el-tag v-if="form.state === 0" style="cursor: pointer" :type="'warning'">未交费</el-tag>
                <el-tag v-if="form.state === 1" style="cursor: pointer" :type="'success'">已交费：{{form.paidPrice+'元'}}</el-tag>
                <el-tag v-if="form.state === 2" style="cursor: pointer" :type="'success'">线下交费：{{form.paidPrice+'元'}}</el-tag>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="tianjia!=true">
            <el-form-item label="所在小区" prop="estateId" >
              <el-select v-model="form.estateId" placeholder="请选择小区" size="mini" style="width:100%;" filterable clearable>
                <el-option v-for="estate in estatesOptions"
                           :key="estate.id"
                           :label="estate.estateName"
                           :value="estate.id"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if="tianjia!=false">
            <el-form-item label="房屋类型" prop="roomType" >
              <el-select v-model="form.roomType" placeholder="请选择房屋类型" size="mini" style="width:100%;" filterable clearable>
                <el-option label="高层" value=0 >高层</el-option>
                <el-option label="多层" value=1 >多层</el-option>
                <el-option label="商业" value=2 >商业</el-option>
                <el-option label="别墅" value=3 >别墅</el-option>
                <el-option label="其他" value=4 >其他</el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="费用类型" prop="feeType">
              <el-select v-model="form.feeType" placeholder="请选择费用类型" size="mini" style="width:90%;" filterable clearable>
                <el-option v-for="dict in feeTypeOptions"
                           :key="dict.dictValue"
                           :label="dict.dictLabel"
                           :value="dict.dictValue"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="是否是车库" prop="isGarage">
              <el-radio-group v-model="form.isGarage" size="mini">
                <el-radio :value="0" :label="0">住宅</el-radio>
                <el-radio :value="1" :label="1">车库</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="房间户号" prop="roomNo">
              <el-input v-model="form.roomNo" placeholder="请输入房间户号" size="mini" style="width: 90%"/>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if="form.feeType == 'wyf'">
            <el-form-item label="房屋面积" prop="roomArea">
              <el-input v-model="form.roomArea" placeholder="请输入房屋面积" size="mini" style="width: 90%">
                <template slot="append">㎡</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="年份" prop="yearNum">
              <el-input v-model="form.yearNum" placeholder="请输入年份" size="mini" style="width: 90%">
                <template slot="append">年</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="月份" prop="monthNum">
              <el-input v-model="form.monthNum" placeholder="请输入月份" size="mini" style="width: 90%">
                <template slot="append">月份</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="姓名" prop="realName">
              <el-input v-model="form.realName" placeholder="请输入姓名" size="mini" style="width: 90%"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="手机号" prop="phoneNum">
              <el-input v-model="form.phoneNum" placeholder="请输入手机号" size="mini" style="width: 90%"/>
            </el-form-item>
          </el-col>


          <el-col :span="12" v-if="form.feeType == 'water' || form.feeType == 'eletrict'">
            <el-form-item label="起止数" prop="beginCount">
              <el-input v-model="form.beginCount" placeholder="请输入起数" size="mini" style="width:100px;"/> ~
              <el-input v-model="form.endCount" placeholder="请输入止数" size="mini" style="width:100px;"/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="数量" prop="paidCount">
              <el-input  v-model="form.paidCount" type="number" placeholder="请输入数量" size="mini" style="width: 90%"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单价" prop="singlePrice">
              <el-input v-model="form.singlePrice" type="number" placeholder="请输入单价" size="mini" style="width: 90%">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="当前应交" prop="totalPrice">
              <el-input v-model="form.totalPrice" type="number" placeholder="请输入当前月份应交" size="mini" style="width: 90%">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="优惠金额" prop="youhuiPrice">
              <el-input v-model="form.youhuiPrice" type="number" placeholder="请输入优惠金额" size="mini" style="width: 90%">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>


          <el-col :span="12" v-if="form.feeType == 'car'">
            <el-form-item label="车牌号" prop="carNum">
              <el-input v-model="form.carNum" placeholder="请输入车牌号" size="mini" style="width: 90%"/>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="备注信息" prop="remark">
              <el-input type="textarea" rows="2" v-model="form.remark" placeholder="请输入备注信息" size="mini"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" size="mini" type="primary" @click="submitForm">确 定</el-button>
<!--        <el-button :loading="buttonLoading" v-if="form.isCanEdit === 1" size="mini" v-hasPermi="['module:feeOrderTemp:update']" type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel" size="mini">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改物业费相关费用的模板对话框 -->
    <el-dialog :title="titleState" :visible.sync="openState" width="550px" append-to-body>
      <el-form ref="form" :model="formState" :rules="rules" label-width="100px">
        <el-form-item label="状态" prop="state">
          <el-radio-group v-model="formState.state" size="mini">
            <el-radio :value="0" :label="0" v-hasPermi="['module:feeOrderTemp:state']">未交费</el-radio>
            <el-radio :value="1" :label="1">已缴费</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" size="mini" type="primary" @click="submitFormState">确 定</el-button>
        <el-button @click="cancelState" size="mini">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 按年生成物业费 -->
    <el-dialog :title="titleAddTemp" :visible.sync="openAddTemp" width="400px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="需生成物业费的年份" prop="year">
              <el-select v-model="form.year" placeholder="选择生成年份" clearable style="width:140px;" size="mini">
                <el-option label="2020年" :value="2020"/>
                <el-option label="2021年" :value="2021"/>
                <el-option label="2022年" :value="2022"/>
                <el-option label="2023年" :value="2023"/>
                <el-option label="2024年" :value="2024"/>
                <el-option label="2025年" :value="2025"/>
                <el-option label="2026年" :value="2026"/>
                <el-option label="2027年" :value="2027"/>
                <el-option label="2028年" :value="2028"/>
                <el-option label="2029年" :value="2029"/>
                <el-option label="2030年" :value="2030"/>
                <el-option label="2031年" :value="2031"/>
                <el-option label="2032年" :value="2032"/>
                <el-option label="2033年" :value="2033"/>
                <el-option label="2034年" :value="2034"/>
                <el-option label="2035年" :value="2035"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="需生成物业费的月份" prop="month">
            <el-select v-model="form.month" placeholder="选择生成月份" clearable style="width:140px;" size="mini"
                       multiple>
              <el-option label="1月份" :value="1"/>
              <el-option label="2月份" :value="2"/>
              <el-option label="3月份" :value="3"/>
              <el-option label="4月份" :value="4"/>
              <el-option label="5月份" :value="5"/>
              <el-option label="6月份" :value="6"/>
              <el-option label="7月份" :value="7"/>
              <el-option label="8月份" :value="8"/>
              <el-option label="9月份" :value="9"/>
              <el-option label="10月份" :value="10"/>
              <el-option label="11月份" :value="11"/>
              <el-option label="12月份" :value="12"/>
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" size="mini" type="primary" @click="submitFormAddTempByYear">确 定
        </el-button>
        <el-button @click="cancelAddTemp" size="mini">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改物业费相关费用的模板对话框 -->
    <el-dialog :title="titleRemark" :visible.sync="openRemark" width="550px" append-to-body>
      <el-form ref="form" :model="formRemark" :rules="rules" label-width="100px">
        <el-form-item label="备注信息" prop="remark">
          <el-input type="textarea" rows="2" v-model="formRemark.remark" placeholder="请输入备注信息" size="mini"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" size="mini" type="primary" @click="submitFormRemark">确 定</el-button>
        <el-button @click="cancelState" size="mini">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 物业费导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport + '&estateId=' + queryParams.estateId"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
<!--          <div class="el-upload__tip" slot="tip">-->
<!--            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据-->
<!--          </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplateWyf">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false" size="mini">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 物业费导入对话框 -->
    <el-dialog :title="uploadWyfYear.title" :visible.sync="uploadWyfYear.open" width="400px" append-to-body>
      <el-upload
        ref="uploadWyfYear"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="uploadWyfYear.headers"
        :action="uploadWyfYear.url + '?updateSupport=' + uploadWyfYear.updateSupport + '&estateId=' + queryParams.estateId"
        :disabled="uploadWyfYear.isUploading"
        :on-progress="handleFileUploadProgressWyfYear"
        :on-success="handleFileWyfYearSuccess"
        :auto-upload="false"
        drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
<!--          <div class="el-upload__tip" slot="tip">-->
<!--            <el-checkbox v-model="uploadWyfYear.updateSupport" /> 是否更新已经存在的用户数据-->
<!--          </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplateWyfYear">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="submitFileFormWyfYear">确 定</el-button>
        <el-button @click="uploadWyfYear.open = false" size="mini">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 水电加压导入对话框 -->
    <el-dialog :title="uploadSdJ.title" :visible.sync="uploadSdJ.open" width="400px" append-to-body>
      <el-upload
        ref="uploadSdJ"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="uploadSdJ.headers"
        :action="uploadSdJ.url + '?updateSupport=' + uploadSdJ.updateSupport + '&estateId=' + queryParams.estateId"
        :disabled="uploadSdJ.isUploading"
        :on-progress="handleFileUploadProgressSdJ"
        :on-success="handleFileSuccessSdJ"
        :auto-upload="false"
        drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
<!--          <div class="el-upload__tip" slot="tip">-->
<!--            <el-checkbox v-model="uploadSdJ.updateSupport" /> 是否更新已经存在的用户数据-->
<!--          </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplateSdJ">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="submitFileFormSdJ">确 定</el-button>
        <el-button @click="uploadSdJ.open = false" size="mini">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTemplate, getTemplate, delTemplate, addTemplate, updateTemplate, exportTemplate,
  importTemplateWyf, importTemplateSdJ, batchUpdateTemplate, offlineExportTemplate, NubTemplate, NubInfoTemplate,batchUpdateOldTemplate
} from "@/api/module/estate/wyfTemplate";
  import { getToken } from "@/utils/auth";
  import { listAllEstate } from "@/api/module/estate/estate";
import {addTempByRoomYear, addTempByYear} from "@/api/module/estate/room";

  export default {
    name: "Template",
    data() {
      return {
        tianjia:false,
        activeName:'wyf',
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 物业费相关费用的模板表格数据
        templateList: [],
        estatesOptions:[],
        feeTypeOptions:[],
        // 弹出层标题
        title: "",
        titleState:"",
        titleRemark:'',
        daoru:false,
        daochu:false,
        caozuo:false,
        totalFee:["正在统计","正在统计","正在统计","正在统计","正在统计","正在统计","正在统计","正在统计",],
        tongji:false,
        // 是否显示弹出层
        open: false,
        openState: false,
        openRemark: false,
        fromType:'',
        dateRange:[],
        openAddTemp: false,
        xiugai:undefined,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          estateId: undefined,
          roomId:undefined,
          realName: undefined,
          roomNo: undefined,
          feeType:undefined,
          state:undefined,
          isArrears:undefined,
          beginDate:undefined,
          endDate:undefined,
          type:undefined,
          xianshangBeginDate:undefined,
          xianshangEndDate:undefined,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          estateId: [
            { required: true, message: "请选择所在小区", trigger: "blur" }
          ],
          roomNo: [
            { required: true, message: "房间户号不能为空", trigger: "blur" }
          ],
          feeType: [
            { required: true, message: "请选择费用类型", trigger: "blur" }
          ],
          yearNum: [
            { required: true, message: "收费年份不能为空", trigger: "blur" }
          ],
          monthNum: [
            { required: true, message: "收费月份不能为空", trigger: "blur" }
          ],
          realName: [
            { required: true, message: "户主姓名不能为空", trigger: "blur" }
          ],
          phoneNum: [
            { required: true, message: "户主手机号不能为空", trigger: "blur" }
          ],
          singlePrice: [
            { required: true, message: "费用单价不能为空", trigger: "blur" }
          ],
          totalPrice: [
            { required: true, message: "应收金额不能为空", trigger: "blur" }
          ],
        },
        formState:{
          ids: [],
          state:undefined,
        },
        formRemark:{
          ids: [],
          remark:undefined,
        },
        // 物业费导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "物业费数据导入",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/module/property/feeOrder/template/importDataWyf"
        },

        // 物业费导入参数
        uploadWyfYear: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "物业费数据导入(按年)",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/module/property/feeOrder/template/importDataWyfYear"
        },

        // 物业费导入参数
        uploadSdJ: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "水电加压数据导入",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/module/property/feeOrder/template/importDataSdJ"
        },
      };
    },
    created() {
      console.log('section  this.$route.query',this.$route.query);
      this.queryParams.estateId = this.$route.query.estateId ? this.$route.query.estateId : 0;
      this.queryParams.roomId = this.$route.query.roomId ? this.$route.query.roomId : undefined;
      this.queryParams.state = this.$route.query.state ? this.$route.query.state : undefined;
      this.fromType = this.$route.query.from ? this.$route.query.from : undefined;
      this.queryParams.isArrears = this.$route.query.arrears ? this.$route.query.arrears : undefined;


      this.getDicts("wyf_fee_type").then(response => {
        this.feeTypeOptions = response.data;
        console.log('this.feeTypeOptions[0].dictValue',this.feeTypeOptions[0].dictValue);
        this.queryParams.feeType = this.feeTypeOptions[0].dictValue;
        this.getList();
      });
    },
    methods: {
      /** 查询物业费相关费用的模板列表 */
      getList() {
        this.loading = true;
        console.log('this.queryParams',this.queryParams);
        listTemplate(this.queryParams).then(response => {
          this.templateList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      handleAddTempByYear() {
        this.openAddTemp = true;
        this.titleAddTemp = "按照年份添加物业费模板";
        this.reset();
      },
      /**
       *  按年生成物业费
       */
      submitFormAddTempByYear() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            console.log('this.form', this.form)
            this.form.id = this.queryParams.roomId;
            if (this.form.id != null && this.form.year != null) {
              addTempByRoomYear(this.form).then(response => {
                this.msgSuccess("生成成功");
                this.openAddTemp = false;
                this.getList();3
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      cancelAddTemp() {
        this.openAddTemp = false;
        this.reset();
      },
      handleClick(val){
        console.log('handleClick',val.name);
        this.activeName = val.name;
        this.queryParams.feeType = val.name;
        this.getList();
      },
      getEstateList() {
        listAllEstate().then(response => {
          this.estatesOptions = response.data;
        });
      },
      caozuo1(){
        this.caozuo=true
      },
      daoru1(){
        this.daoru=true
      },
      daochu1(){
        this.daochu=true
      },
      guanbi1(){
        this.daoru=false
      },
      guanbi2(){
        this.daochu=false
      },
      guanbi3(){
        this.caozuo=false
      },
      tongji1(){
        if (this.tongji==false){
          this.tongji=true
        }else {
          this.tongji=false
        }
        if (this.totalFee[0]=="正在统计"){
          this.getNub();
        }
      },
      getNub(){
        NubInfoTemplate(this.queryParams).then(response => {
          console.log(response)
          this.totalFee = response;
        });
      },
      // 取消按钮
      cancel() {
        this.xiugai = undefined;
        this.open = false;
        this.reset();
      },
      // 取消按钮
      cancelState() {
        this.openState = false;
        this.resetState();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          estateId: this.queryParams.estateId,
          estateName: undefined,
          realName: undefined,
          roomNo: undefined,
          feeOrderId: undefined,
          roomArea: undefined,
          roomId: this.queryParams.roomId,
          phoneNum: undefined,
          carNum: undefined,
          feeType: undefined,
          isGarage:undefined,
          yearNum: undefined,
          roomType: undefined,
          monthNum: undefined,
          singlePrice: undefined,
          totalPrice: undefined,
          paidPrice: undefined,
          youhuiPrice: undefined,
          unPayPrice: undefined,
          paidCount: undefined,
          isBand: undefined,
          bangWxUserId: undefined,
          beginCount:undefined,
          endCount:undefined,
          state: undefined,
          remark: undefined,
          payDate: undefined,
          paidMonth: undefined,
          createTime: undefined,
        };
        this.resetForm("form");
      },
      resetState(){
        this.formState = {
          ids: [],
          state:undefined,
        };
        this.resetForm("formState");
      },
      resetRemark(){
        this.formRemak = {
          ids: [],
          remark:undefined,
        };
        this.resetForm("formRemark");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        console.log('dateRange',this.dateRange);
        if(this.dateRange !=undefined && this.dateRange.length === 2){
          if (this.$route.query.state==2){
            this.queryParams.beginDate = this.dateRange[0];
            this.queryParams.endDate = this.dateRange[1];
            this.queryParams.pageSize=10;
          }else if (this.$route.query.state==1){
            this.queryParams.xianshangBeginDate = this.dateRange[0];
            this.queryParams.xianshangEndDate = this.dateRange[1];
            this.queryParams.pageSize=1000;
          }
        }
        this.getNub();
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id);
        this.single = selection.length!==1;
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.getEstateList();
        this.tianjia = true;
        if (this.templateList.length>0){
          getTemplate(this.templateList[this.templateList.length-1].id).then(response => {
            this.loading = false;
            this.form = response.data;
            this.form.monthNum = undefined;
            this.form.id = undefined;
            this.open = true;
            this.xiugai = 0;
            this.title = "添加物业费相关费用的模板";
          });
        }else {
          this.open = true;
          this.xiugai = 0;
          this.title = "添加物业费相关费用的模板";
        }
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.loading = true;
        this.reset();
        this.getEstateList();
        const id = row.id || this.ids;
        getTemplate(id).then(response => {
          this.loading = false;
          this.form = response.data;
          if(this.form.feeType =='car'){
            this.form.paidCount = parseInt(this.form.paidCount+'');
          }
          this.open = true;
          this.title = "修改物业费相关费用的模板";
        });
      },
      handleUpdateState(){
        // this.loading = true;
        this.resetState();
        this.openState = true;
        this.titleState = "批量修改交费状态";
      },
      handleUpdateRemark(){
        // this.loading = true;
        this.resetRemark();
        this.openRemark = true;
        this.titleRemark = "批量修改备注信息";
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateTemplate(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addTemplate(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.xiugai = undefined;
                this.tianjia= false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除物业费相关费用的模板编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delTemplate(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
      },
      submitFormState(){
        const ids = this.ids;
        this.formState.ids = ids;
        console.log('this.formState',this.formState);
        batchUpdateOldTemplate(this.formState).then(response => {
          if(response.code === 200){
            this.getList();
            this.openState = false;
            this.msgSuccess(response.msg);
          }else{
            this.msgError("修改失败");
          }
        });

        // this.$confirm('是否确认批量修改数据项?', "警告", {
        //   confirmButtonText: "确定",
        //   cancelButtonText: "取消",
        //   type: "warning"
        // }).then(() => {
        //   this.loading = true;
        // }).then(() => {
        //   this.loading = false;
        //   this.getList();
        //   this.msgSuccess("删除成功");
        // }).catch(() => {});
      },
      submitFormRemark(){
        const ids = this.ids;
        this.formRemark.ids = ids;
        console.log('this.formRemark',this.formRemark);
        batchUpdateTemplate(this.formRemark).then(response => {
          if(response.code === 200){
            this.getList();
            this.openRemark = false;
            this.msgSuccess(response.msg);
          }else{
            this.msgError("修改失败");
          }
        });
      },


      /** 导出按钮操作 */
      handleExport() {
        this.queryParams.type = undefined;
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有物业费相关费用的模板数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportTemplate(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      },

      handleExportAll() {
        this.queryParams.type = 1;
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有物业费相关费用的模板数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportTemplate(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
          this.queryParams.type == undefined;
        }).catch(() => {});
      },

      /** 导出线下缴费按钮操作 */
      handleOfflineExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出物业费线下缴费的模板数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return offlineExportTemplate(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      },

      /** 导入按钮操作 */
      handleImportWyf() {
        this.upload.title = "物业费数据导入";
        this.upload.open = true;
      },
      handleImportWyfYear() {
        this.uploadWyfYear.title = "物业费数据导入(按年)";
        this.uploadWyfYear.open = true;
      },
      /** 导入按钮操作 */
      handleImportSdJ() {
        this.uploadSdJ.title = "水电加压数据导入";
        this.uploadSdJ.open = true;
      },
      /** 下载模板操作 */
      importTemplateWyf() {
        // importTemplateWyf().then(response => {
        //   this.download("https://www.caihengyun.com/chyimg/file/temp/%E7%89%A9%E4%B8%9A%E8%B4%B9%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx");
        // });
        // this.download("");
        window.location.href = "https://www.caihengyun.com/chyimg/file/temp/%E7%89%A9%E4%B8%9A%E8%B4%B9%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx";
      },
      /** 下载模板操作 */
      importTemplateWyfYear() {
        // importTemplateWyf().then(response => {
        //   this.download("https://www.caihengyun.com/chyimg/file/temp/%E7%89%A9%E4%B8%9A%E8%B4%B9%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx");
        // });
        // this.download("");
        window.location.href = "https://www.caihengyun.com/chyimg/file/temp/%E7%89%A9%E4%B8%9A%E8%B4%B9%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF-%E6%8C%89%E5%B9%B4%E7%94%9F%E6%88%90.xlsx";
      },
      /** 下载模板操作 */
      importTemplateSdJ() {
        // importTemplateSdJ().then(response => {
        //   this.download(response.msg);
        // });
        window.location.href = "https://www.caihengyun.com/chyimg/file/temp/%E6%B0%B4%E7%94%B5%E8%B4%B9%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx";
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传中处理
      handleFileUploadProgressWyfYear(event, file, fileList) {
        this.uploadWyfYear.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 文件上传成功处理
      handleFileWyfYearSuccess(response, file, fileList) {
        this.uploadWyfYear.open = false;
        this.uploadWyfYear.isUploading = false;
        this.$refs.uploadWyfYear.clearFiles();
        this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },


      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      },
      submitFileFormWyfYear() {
        this.$refs.uploadWyfYear.submit();
      },

      // 文件上传中处理
      handleFileUploadProgressSdJ(event, file, fileList) {
        this.uploadSdJ.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccessSdJ(response, file, fileList) {
        this.uploadSdJ.open = false;
        this.uploadSdJ.isUploading = false;
        this.$refs.uploadSdJ.clearFiles();
        this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileFormSdJ() {
        this.$refs.uploadSdJ.submit();
      }
    }
  };
</script>
